<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{
        margin: 0;
        padding: 0;
    }
    #big{
        width: 600px;
        height: 600px;
        text-align: center;
        margin: 0 auto;
        background-color: #0000ff;
    }

    #middle{
        width: 400px;
        height: 400px;
        text-align: center;
        position: absolute;
        left: 760px;
        top: 100px;
        background-color: #ffffff;
    }

    #little{
        width: 200px;
        height: 200px;
        text-align: center;
        position: relative;
        left:100px;;
        top: 100px;
        background-color: #ff0000;
        line-height: 200px;
    }
    </style>
</head>
<body>
    <div id="big">
        <div id="middle">
            <div id="little">
                内部框！
            </div>
        </div>
    </div>

    <script type="text/javascript">
    /*方法一
    function showMassage(){
        alert("点击触发事件");
    }

    var a=document.getElementById("big");
    a.addEventListener("click",showMassage,false);

    var b=document.getElementById("middle");
    b.addEventListener("click",showMassage,false);

    var c=document.getElementById("little");
    c.addEventListener("click",showMassage,false);
    */



    /*方法二
    function showMassage(){
        alert("点击触发事件");
    }

    var a=document.getElementById("big");
    a.onclick=function(){
        showMassage("大框");
    }

    var b=document.getElementById("middle");
    b.onclick=function(){
        showMassage("中框");
    }

    var c=document.getElementById("little");
    c.onclick=function(){
        showMassage("小框");
    }
    */



    //阻止事件冒泡
    function showMassage(Msg){
        alert("点击触发"+Msg);
    }

    var a=document.getElementById("big");
    a.onclick=function(){
        showMassage("大框");
        window.event.cancelBubble=true;
    }

    var b=document.getElementById("middle");
    b.onclick=function(){
        showMassage("中框");
        window.event.cancelBubble=true;
    }

    var c=document.getElementById("little");
    c.onclick=function(){
        showMassage("小框");
        window.event.cancelBubble=true;
    }
    </script>
</body>
</html>